#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <list>
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_CommHdr.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_Types.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/XyRyNet_ProtocolHdr.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine/NetEngine_Core/NetCore_Define.h"
#include "../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine/NetEngine_Core/NetCore_Error.h"

//g++ -std=gnu++11 -Wall -g TestSocket_EPoll.cpp -o TestSocket_EPoll -L ../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_Lib/NetEngine_BaseLib -L ../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_Lib/NetEngine_Algorithm -L ../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine/NetEngine_ManagePool -L ../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine/NetEngine_Core -lNetEngine_BaseLib -lNetEngine_Algorithm -lNetEngine_ManagePool -lNetEngine_Core -Wl,-rpath=../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_Lib/NetEngine_BaseLib:../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine_Lib/NetEngine_Algorithm:../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine/NetEngine_ManagePool:../../../NetEngine_Linux/NetEngine_SourceCode/NetEngine/NetEngine_Core,--disable-new-dtags


XNETHANDLE xhNet;
BOOL NetCore_CBLogin(LPCTSTR lpszClientAddr,SOCKET hSocket,LPVOID lParam)
{
    NetCore_TCPEPoll_SetLimitEx(xhNet, lpszClientAddr, 10, _T("hello"));
    printf("%s,%d，进入服务器\n",lpszClientAddr,hSocket);
    return TRUE;
}
void NetCore_CBRecv(LPCTSTR lpszClientAddr,SOCKET hSocket,LPCTSTR lpszRecvMsg,int nMsgLen,LPVOID lParam)
{
    printf("%s,%d,数据：%d,%s\n",lpszClientAddr,hSocket,nMsgLen,lpszRecvMsg);
}
void NetCore_CBLeave(LPCTSTR lpszClientAddr,SOCKET hSocket,LPVOID lParam)
{
    printf("%s,%d离开服务器\n",lpszClientAddr,hSocket);
}

int main()
{
    if (!NetCore_TCPEPoll_StartEx(&xhNet))
    {
        perror("main");
    }
    NetCore_TCPEPoll_RegisterCallBackEx(xhNet,NetCore_CBLogin,NetCore_CBRecv,NetCore_CBLeave);
    printf("启动成功\n");

    for (int i = 0;i < 999999;i++)
    {
        sleep(1);
    }
    NetCore_TCPEPoll_DestroyEx(xhNet);
    return 0;
}
